/*
 * Copyright (c) Zhongkehonglue Technologies Co., Ltd. 2025. All rights reserved.
 * Description: Implementation of functions related to the DMC module.
 * Author: wangchunyang
 * Create: 2025-05-23
 */

#ifndef DMC_ENV_H
#define DMC_ENV_H

#include <string>
#include <atomic>
#include <mutex>

#include "upnp.h"
#include "upnpapi.h"
#include "dmcApiTypes.h"
#include "dmcPeriodicTask.h"

namespace DlnaDmc {
class DmcEnv {
public:
    DmcEnv(const DmcEnv&) = delete;
    DmcEnv(DmcEnv&&) = delete;
    DmcEnv& operator=(const DmcEnv&) = delete;
    DmcEnv& operator=(DmcEnv&&) = delete;
    dmc_int32 InitEnv(const std::string &ifName, const DmcCbType &cb);
    dmc_int32 DestroyEnv();
    dmc_int32 SendMSearch();
    UpnpClient_Handle GetClientHdl();
    bool IsInited();
    static dmc_int32 ReSearchAsync(void *data);

    static DmcEnv& GetInstance() {
        return instance;
    }

private:
    static DmcEnv instance;
    DmcEnv() {};

    UpnpClient_Handle clientHdl;
    std::atomic<bool> envInited{false};
    std::mutex initMtx;
    PeriodicTask task;
};

}
#endif /* DMC_ENV_H */

